package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.gdms.service.UPstudentservice;
import com.zr.gdms.serviceimpl.UPstudentserviceimpl;


import net.sf.json.JSONObject;

public class UPstudentController extends HttpServlet {
	UPstudentservice us=new UPstudentserviceimpl();
		@Override
		protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			// TODO Auto-generated method stub
			doPost(req, resp);
		}
		@Override
		protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
			resp.setCharacterEncoding("utf8");
			int sid=Integer.parseInt(req.getParameter("sid"));
			String sname=req.getParameter("sname");
			String sage=req.getParameter("sage");
			String ssex=req.getParameter("ssex");
			String sdepart=req.getParameter("sdepart");
			String stel=req.getParameter("stel");
			String sstate=req.getParameter("sstate");
			HttpSession session =req.getSession();
			PrintWriter pt=resp.getWriter();
			boolean flag=us.updateStudent(sid, sname, sage, ssex, sdepart, stel, sstate);
			if(flag){		
				JSONObject result=new JSONObject(); 
				  result.put("success", "true");
				  result.put("errorMsg", "修改成功"); 		 
				  pt.write(result.toString());
				  resp.sendRedirect("student.jsp");
			}else{
				  session.setAttribute("Msg", "修改失败");
				  resp.sendRedirect("student.jsp");
			}
				
		}
}
